<template>
  <div>
    <el-container>
      <el-aside width="200px">
        <div class="logo">
          <img src="/logo.png" alt="" />
        </div>
        <el-menu
          default-active="/commodity"
          class="el-menu-vertical-demo"
          background-color="rgb(51, 65, 87)"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="!flag"
          router
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>基础管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/commodity">商品管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>订单管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/order">交易订单</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>系统管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/one">用户管理</el-menu-item>
              <el-menu-item index="/two">菜单管理</el-menu-item>
              <el-menu-item index="/three">角色管理</el-menu-item>
              <el-menu-item index="/four">公司管理</el-menu-item>
              <el-menu-item index="/five">系统环境变量</el-menu-item>
              <el-menu-item index="/six">权限管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>支付管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/seven">支付配置信息</el-menu-item>
              <el-menu-item index="/eight">支付配置</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-menu
            class="el-menu-demo"
            mode="horizontal"
            background-color="rgb(51, 65, 87)"
            text-color="#fff"
          >
            <div class="icons">
              <i class="el-icon-s-fold" v-show="flag" @click="collapse"></i>
              <i
                class="el-icon-s-unfold"
                v-show="!flag"
                @click="noCollapse"
              ></i>
            </div>
            <el-submenu index="2">
              <template slot="title">超级管理员</template>
              <el-menu-item index="2-1" style="text-align: center" @click="exit"
                >退出</el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-header>
        <el-main>
          <div style="margin: 20px 0">
            <Crumb></Crumb>
          </div>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import Crumb from "../components/Crumb";
export default {
  data() {
    return {
      flag: true,
    };
  },

  methods: {
    collapse() {
      this.flag = false;
      document.querySelector(".el-aside").style.width = "64px";
    },
    noCollapse() {
      this.flag = true;
      document.querySelector(".el-aside").style.width = "200px";
    },
    //退出
    exit() {
      this.$confirm("退出登录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          localStorage.removeItem("token");
          this.$router.push({ path: "/login" });
          this.$message({
            type: "success",
            message: "退出成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出",
          });
        });
    },
  },
  components: {
    Crumb,
  },
};
</script>
<style lang="scss" scoped>
.logo {
  background-color: rgb(51, 65, 87);
  padding: 16px 0;
  text-align: center;
  border-right: solid 1px #e6e6e6;
  min-width: 65px;
}
.el-aside {
  height: 100%;
  overflow: hidden;
  transition: all 0.4s;
  .el-menu {
    li {
      min-width: 199px !important;
    }
  }
}
.el-header {
  background-color: rgb(51, 65, 87);
  color: #fff;
  padding: 0;

  .el-menu {
    width: 100%;
    li {
      float: right;
      margin: 0;
    }
    .icons {
      width: 60px;
      height: 60px;
      float: left;
      display: flex;
      align-items: center;
      justify-content: center;
      outline: none;
    }
  }
}
</style>